import mysql.connector
import pandas as pd

def get_column_stats(column_name, table_name, host="localhost", user="root", password="password", database="test_db"):
    # 连接到 MySQL 数据库
    db = mysql.connector.connect(
        host=host,
        user=user,
        password=password,
        database=database
    )

    # 创建游标对象
    cursor = db.cursor()

    # 从数据库中查询指定列的数据
    query = f"SELECT {column_name} FROM {table_name}"
    cursor.execute(query)

    # 将查询结果转换为 pandas DataFrame
    data = cursor.fetchall()
    df = pd.DataFrame(data, columns=[column_name])

    # 计算统计信息
    mean = df[column_name].mean()
    std_dev = df[column_name].std()
    max_value = df[column_name].max()
    min_value = df[column_name].min()

    # 关闭游标和数据库连接
    cursor.close()
    db.close()


    # 返回统计结果
    return {
        "mean": mean,
        "std_dev": std_dev,
        "max_value": max_value,
        "min_value": min_value
    }

# 示例调用
columns = {"commits","prs","issues","total_start","forks","start","public_repos","followers"}
for column in columns:
    column_stats = get_column_stats(column, "developer", host="localhost", user="root", password="123456", database="assess")
    print(column)
    print("均值:", column_stats["mean"])
    print("标准差:", column_stats["std_dev"])
    print("最大值:", column_stats["max_value"])
    print("最小值:", column_stats["min_value"])





